package com.example.smartcity.ui.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.recommendBean;

import java.util.ArrayList;

public class RecommendShopAdapter extends BaseAdapter {
    int Resource;
    ArrayList list;
    public  RecommendShopAdapter(int Resource, ArrayList list){
        this.Resource = Resource;
        this.list = list;
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        recommendBean bean = (recommendBean) getItem(position);
        View view = null;
        MyViewHolder viewHolder = null;
        if (convertView==null){
            view = LayoutInflater.from(parent.getContext()).inflate(Resource,parent,false);
            viewHolder = new MyViewHolder();
            viewHolder.TVMessageManery = view.findViewById(R.id.TV_messageManery);
            viewHolder.TVMessageState = view.findViewById(R.id.TV_MessageState);
            viewHolder.TVTitle = view.findViewById(R.id.TV_title);
            viewHolder.TV_POsition = view.findViewById(R.id.TV_POsition);
            view.setTag(viewHolder);
        }else{
            view = convertView;
            viewHolder = (MyViewHolder) view.getTag();
        }
        viewHolder.TVTitle.setImageResource(bean.getBackground());
        viewHolder.TVMessageState.setText(bean.getState());
        viewHolder.TVMessageManery.setText(bean.getMoney());
        viewHolder.TV_POsition.setText(bean.getTitle());
        return view;
    }
    static class MyViewHolder{
        private ImageView TVTitle;
        private TextView TVMessageState;
        private TextView TVMessageManery;
        private TextView TV_POsition;
    }
}
